<?php
namespace app\index\controller;

use PHPHtmlParser\Dom;

class Index
{
    public function index()
    {
        return str_replace(' - 中国武宁网——武宁县委县政府门户网站','','水利局 - 中国武宁网——武宁县委县政府门户网站');
    }

    public function monitor()
    {
        debug('begin');
        $webUrls = [
         'http://fwzx.wuning.gov.cn',
         'http://nfb.wuning.gov.cn',
         'http://scjg.wuning.gov.cn',
         'http://wjw.wuning.gov.cn',
         'http://fyb.wuning.gov.cn',
         'http://slj.wuning.gov.cn',
         'http://jtys.wuning.gov.cn',
         'http://nyj.wuning.gov.cn'
         ];

        $dom = new Dom;

        $dateLists = [];
        foreach ($webUrls as $webUrl) {
            $dom->load($webUrl);
            $categoryUrl = $dom->find('#mainNav li h4 a',1)->getAttribute('href');
            $categoryUrl = $webUrl.$categoryUrl;
            $dom->load($categoryUrl);
            $dates = $dom->find('.newsList li span');
            $dateList = [];
            foreach ($dates as $date) {
                $dateList[] = $date->innerHtml();
            }
            $dateLists[] = $dateList;
        }
        // $dom->load('http://fwzx.wuning.gov.cn/Category_1587/Index.aspx');
        // $dates = $dom->find('.newsList li');
        // foreach ($dates as $date) {
        //     echo $date->innerHtml;
        // }
        dump($dateLists);
        echo debug('begin','end');
    }
}
